import axios from 'axios'

// create an axios instance
const service = axios.create({
	baseURL: 'http://service.picasso.adesk.com/', // url = base url + request url
	// withCredentials: false, 
	// send cookies when cross-domain requests
	// 注意：withCredentials和后端配置的cross跨域不可同时使用
	timeout: 6000, // request timeout
	crossDomain: true
})

// request拦截器,在请求之前做一些处理
service.interceptors.request.use(config => {
		//添加请求头
		config.headers["accessToken"] = "123";
		// console.log('请求拦截成功')
		return config;
		
	},
	error => {
		console.log(error); // for debug
		return Promise.reject(error);
	}
);

//配置成功后的拦截器
service.interceptors.response.use(res => {
	// console.log(res)
	if (res.status == 200 ) {
		return Promise.resolve(res.data)
	} else {
		return Promise.reject(res.errMsg);
	}
}, error => {
	// console.log(error.response.status)
	if (error.response.status) {
		switch (error.response.status) {
			case 401:
				break;
			default:
				break;
		}
	}
	return Promise.reject(error)
})




export default service
